//
//  HSatisSave.m
//  NursingManages
//
//  Created by Zhen Huang on 17/7/3.
//  Copyright © 2017年 huangzhen. All rights reserved.
//

#import "HSatisSave.h"
#import "DBHelper.h"

@implementation HSatisSave


-(instancetype)initWithFormData:(NSArray *)bigModelArray{
    
    NSArray *array =   [self GetInspectDetailSql:bigModelArray];
    
    @try {
        
        [DBHelper.DB open];
        [DBHelper.DB beginTransaction];
        
        
        for (NSString  * sql  in array) {
            [DBHelper.DB executeUpdate:sql];
        }
        
        [DBHelper.DB commit];
        
        
    } @catch (NSException *exception) {
        
        [DBHelper.DB rollback];
        NSLog(@"发现错误，数据已回滚：%@",exception);
        
    } @finally {
        [DBHelper.DB close];
    }
    
    return self;
}
-(NSArray*) GetInspectDetailSql:(NSArray*)arr{
    
    NSMutableArray *arrSql = [[NSMutableArray alloc]init];
    for (Model_Hr_Satisfaction* model in arr) {
        NSString *sql1 = @"insert into hr_satisfaction_detail(";
        NSString *sql2 = @" values(";
        
        sql1 = [sql1 stringByAppendingString:@"sat_period,"];
        sql2 = [sql2 stringByAppendingString:[NSString stringWithFormat:@"'%@',",model.SAT_PERIOD]];
        
        sql1 = [sql1 stringByAppendingString:@"item_code,"];
        sql2 = [sql2 stringByAppendingString:[NSString stringWithFormat:@"'%@',",model.ITEM_CODE]];
        
        sql1 = [sql1 stringByAppendingString:@"item_score,"];
        sql2 = [sql2 stringByAppendingString:[NSString stringWithFormat:@"'%f',",model.ITEM_SCORE]];
        
        sql1 = [sql1 stringByAppendingString:@"dept_code,"];
        sql2 = [sql2 stringByAppendingString:[NSString stringWithFormat:@"'%@',",model.DEPT_CODE]];
        
        sql1 = [sql1 stringByAppendingString:@"table_code,"];
        sql2 = [sql2 stringByAppendingString:[NSString stringWithFormat:@"'%@',",model.TABLE_CODE]];
        
        sql1 = [sql1 stringByAppendingString:@"sat_des,"];
        sql2 = [sql2 stringByAppendingString:[NSString stringWithFormat:@"'%@',",model.SAT_DES]];
        
        sql1 = [sql1 stringByAppendingString:@"sat_type,"];
        sql2 = [sql2 stringByAppendingString:[NSString stringWithFormat:@"'%@',",model.SAT_TYPE]];
        
        sql1 = [sql1 stringByAppendingString:@"modify_date,"];
        sql2 = [sql2 stringByAppendingString:[NSString stringWithFormat:@"'%@',",model.MODIFY_DATE]];
        
        sql1 = [sql1 stringByAppendingString:@"modifier,"];
        sql2 = [sql2 stringByAppendingString:[NSString stringWithFormat:@"'%@',",model.MODIFIER]];
        
        sql1 = [sql1 stringByAppendingString:@"temp_col,"];
        sql2 = [sql2 stringByAppendingString:[NSString stringWithFormat:@"'%@',",model.TEMP_COL]];
        
        sql1 = [sql1 stringByAppendingString:@"item_id,"];
        sql2 = [sql2 stringByAppendingString:[NSString stringWithFormat:@"'%@',",model.ITEM_ID]];
        
         
        sql1 = [sql1 stringByAppendingString:@"sat_des2,"];
        sql2 = [sql2 stringByAppendingString:[NSString stringWithFormat:@"'%@',",model.SAT_DES2]];
        
        
        sql1 = [sql1 stringByAppendingString:@"upload_flag,"];
        sql2 = [sql2 stringByAppendingString:[NSString stringWithFormat:@"'%ld',",model.UPLOAD_FLAG]];
        

        sql1 = [sql1 stringByAppendingString:@"modify_id,"];
        sql2 = [sql2 stringByAppendingString:[NSString stringWithFormat:@"'%@',",model.MODIFY_ID]];
        
        
        sql1 = [sql1 stringByAppendingString:@"delete_flag,"];
        sql2 = [sql2 stringByAppendingString:[NSString stringWithFormat:@"'%ld',",(long)model.DELETE_FLAG]];
        
        
        sql1 = [sql1 stringByAppendingString:@"status,"];
        sql2 = [sql2 stringByAppendingString:[NSString stringWithFormat:@"'%ld',",(long)model.STATUS]];
        
        
        sql1 = [sql1 stringByAppendingString:@"step_id,"];
        sql2 = [sql2 stringByAppendingString:[NSString stringWithFormat:@"'%@',",model.STEP_ID]];
        
        
        sql1 = [sql1 stringByAppendingString:@"org_id,"];
        sql2 = [sql2 stringByAppendingString:[NSString stringWithFormat:@"'%@',",model.ORG_ID]];
        
        sql1 = [sql1 stringByAppendingString:@"survey_date,"];
        sql2 = [sql2 stringByAppendingString:[NSString stringWithFormat:@"'%@',",model.SURVEY_DATE]];
        
        
        sql1 = [sql1 stringByAppendingString:@"reasons,"];
        sql2 = [sql2 stringByAppendingString:[NSString stringWithFormat:@"'%@',",model.REASONS]];
        
        sql1 = [sql1 stringByAppendingString:@"sat_id"];
        sql2 = [sql2 stringByAppendingString:[NSString stringWithFormat:@"'%@'",model.SAT_ID]];
    
        
        sql1 = [sql1 stringByAppendingString:@")"];
        sql2 = [sql2 stringByAppendingString:@")"];
        NSString *sql3 = [sql1 stringByAppendingString:sql2];
        NSLog(@"detail  %@",sql3);
        
        [arrSql addObject:sql3];
    }
    
    return arrSql;
}




@end
